<?php
/**
 * data adaptor for Sqlite
 * Actually uses PDO...
 * @author bbqq <toughgamer@gmail.com>
 * @package com.blib.data
 * @copyright bbqq qstufie.com
 */
class Blib_Data_Adaptor_Sqlite extends Blib_Data_Adaptor_Pdo
{
    /**
     * construct the adaptor
     *
     * @param array $options
     *
     * @return void
     */
    public function __construct($options = array())
    {
        if (!isset($options['dbname'])) {
            return $this->_error(null, null, 'Option is invalid');
        }

        // we dont want more than 1 connection to the db...
        $key = md5($options['dbname']);
        $dsn = 'sqlite:' . $options['dbname'];
        if (Blib::get($key) instanceof PDO) {
            $this->_pdo = Blib::get($key);
            $this->_pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, TRUE);
            return true;
        }

        try {
            Blib::register($key, new PDO($dsn));
            $this->_pdo = Blib::get($key);
            $this->_pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, TRUE);
        } catch (PDOException $e) {
            // throw our own exception object
            throw new Blib_Exception_Dao(null, null, $e);
        }

    }// end __construct


    /**
     * replace into the db...
     * not supported by sqlite
     */
    public function replaceInto($data, $tableName)
    {
        throw new exception('Replace Into is not supported by SQLite');

    }// end replaceInto


    // quote names
    public function nameQuote($name)
    {
        if (strpos($name, '.') !== false) {
            $name = str_replace('.', '","',  $object->__getTableName());
        }
        return '"' . $name . '"';

    }// end nameQuote

}// end Blib_Data_Adaptor_Sqlite
?>